package me.j360.springboot.simple.bean.search.result;

import me.j360.springboot.simple.bean.search.Search;
import org.springframework.util.Assert;

/**
 * 说明：
 * Bean类 - 返回结果 - 结果
 *
 * ============================================================================
 * 版权所有 2015 qiushihua。
 *
 * @author qiushihua
 * @version 0.1 2015-08-03
 * ============================================================================
 */
public class ResultUnique extends Result {

    private final Object object;

    public Object getObject() {
        return object;
    }

    private ResultUnique(Search search, Object object) {
        super(search);
        this.object = object;
    }

    private static Builder newBuilder() {
        return new Builder();
    }

    public static ResultUnique uniqueResult(Search search, Object object) {
        return newBuilder().setSearch(search).setObjcet(object).build();
    }

    public static class Builder extends Result.Builder<Result, Builder> {

        private Object object;

        @Override
        protected Builder getThis() {
            return this;
        }

        public Builder setSearch(Search search) {
            this.search = search;
            return this;
        }

        public Builder setObjcet(Object object) {
            this.object = object;
            return this;
        }

        @Override
        public ResultUnique build() {
            Assert.notNull(search, "search 不能为空");
            return new ResultUnique(search, object);
        }

    }

}
